package Util;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class DBConn {

    private static Connection conn;
    /**
     * 连接数据库
     */
    public static Connection getConnection() {
        try {
            Class.forName("com.mysql.jdbc.Driver");//注册驱动
            System.out.println("加载成功！");
        } catch (ClassNotFoundException e) {
            System.out.println("加载失败O.o");
            e.printStackTrace();
        }
        try {
            String url = "jdbc:mysql://127.0.0.1:3306/db01?serverTimezone=UTC&useSSL=false";
            String username = "root";
            String password = "123456";
            //2.获取连接对象
            conn = DriverManager.getConnection(url, username, password); //连接数据库
            System.out.println("数据库连接成功！");
        } catch (SQLException e) {
            System.out.println("数据库连接失败");
            e.printStackTrace();
        }
        return conn;
    }

}
